{% extends "tcms_base.html" %}
{% load static %}
{% load extra_filters %}
{% load attachments_tags %}
{% block subtitle %}{{ test_plan.name }}{% endblock %}

{% block custom_stylesheet %}
<link rel="stylesheet" type="text/css" href="{% static 'style/print.css' %}" media="print">
{% endblock %}
{% block custom_javascript %}
<script type="text/javascript" src="{% static 'js/lib/tablednd.js' %}"></script>
<script type="text/javascript" src="{% static 'js/lib/jquery.dataTables.js' %}"></script>
<script type="text/javascript" src="{% static 'js/testplan_actions.js' %}"></script>
<script type="text/javascript" src="{% static 'js/testcase_actions.js' %}"></script>
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
<script type="text/javascript" src="{% static 'admin/js/core.js' %}"></script>
<script type="text/javascript" src="{% static 'admin/js/SelectFilter2.js' %}"></script>
<script type="text/javascript" src="{% static 'admin/js/SelectBox.js' %}"></script>
<script type="text/javascript" src="{% static 'admin/js/calendar.js' %}"></script>
<script type="text/javascript" src="{% static 'admin/js/admin/DateTimeShortcuts.js' %}"></script>

<script type="text/javascript">
Nitrate.Utils.after_page_load(Nitrate.TestPlans.Details.on_load);

Nitrate.TestPlans.Instance = {
	pk: {{ test_plan.pk }},
	fields: {
		name: '{{ test_plan.name }}',
		product_id: {{ test_plan.product_id }},
		author_id: {{ test_plan.author_id }},
		parent: {{ test_plan.parent.pk|default:'null' }}
	},
}
</script>

<!-- temporary workaround so we can convert TestPlans.TreeView.filter to JSON RPC -->
<script src="{% static 'jquery/dist/jquery.min.js' %}"></script>
<script src="{% static 'js/jsonrpc.js' %}"></script>
{% endblock %}

{% block content_type %}
	<input type="hidden" name="content_type" value="testplans.testplan" />
	<input type="hidden" name="object_pk" value="{{ test_plan.pk }}" />
	<input type="hidden" name="name" value="{{ test_plan.name }}" />
{% endblock %}

{% block contents %}
<div id="content">
	<input id="id_plan_id" type="hidden" name="plan_id" value="{{ test_plan.plan_id }}">
	<div class="control">
		<span id="id_buttons" class="button">
			<input id="btn_edit" type="button" value="Edit Plan " title="Edit test plan" data-param="{% url 'plan-edit' test_plan.plan_id %}" {% if perms.testplans.change_testplan %}{% else%}disabled{% endif %}>
			<input id="btn_clone" type="button" value="Clone Plan" title="Clone this plan to other product" data-params='["{% url "plans-clone" %}", {{ test_plan.plan_id }}]' {% if perms.testplans.add_testplan %}{% else %}disabled{% endif %}>
			<input id="btn_print" type="button" value="Print Plan "
                   title="Print Plan"
                   data-params='["{% url "plans-printable" %}", {{ test_plan.pk }}]'>
                    {% if perms.testplans.delete_testplan %}
                        <a href="{% url 'admin:testplans_testplan_delete' test_plan.pk %}"><strong>DELETE PLAN</strong></a>
                    {% endif %}
		</span>
	</div>
	<h2 id="display_title" class="{% ifequal test_plan.is_active 0 %}line-through{% endifequal %}">
		{{ test_plan.name }}
	</h2>
	<div class="listinfo_content">
		<div class="leftlistinfo">
			<div class="listinfo">
				<div class="title grey">Author&nbsp;:</div>
				<div id="display_author"  class="name " > <a href="{% url "tcms-profile" test_plan.author.username %}">{{ test_plan.author.username }}</a></div>
			</div>
			<div class="listinfo">
				<div class="title grey">Owner&nbsp;:</div>
				<div id="display_author"  class="name" >
				{% if test_plan.owner %}
				<a href="{% url "tcms-profile" test_plan.owner.username|default:"unknown" %}">{{ test_plan.owner }}</a>
				{% else %}
				{{ test_plan.owner }}
				{% endif %}
				</div>
			</div>
			<div class="listinfo">
				<div class="title grey">Product&nbsp;:</div>
				<div id="display_product"  class="name "><a href="{% url "plans-search" %}?product={{ test_plan.product_id }}" title="Search plans of {{ test_plan.product }} ">{{ test_plan.product }}</a></div>
			</div>
			<div class="listinfo">
				<div class="title grey">Version&nbsp;:</div>
				<div id="display_product_version"  class="name ">{{ test_plan.product_version.value }}</div>
			</div>
			<div class="listinfo">
				<div class="title grey">Plan Type&nbsp;:</div>
				<div id="display_type"  class="name ">{{ test_plan.type.name }}</div>
			</div>
		 </div>
		<div class="rightlistinfo">
			<div class="listinfo">
				<div class="title grey">Reference Link&nbsp;:</div>
				<div class="name">
					{% if test_plan.extra_link %}
					<a href="{{ test_plan.extra_link }}">{{ test_plan.extra_link }}</a>
					{% else %}
					None
					{% endif %}
				</div>
			</div>
			<div class="listinfo">
				<div class="title grey">Create Time&nbsp;:</div>
				<div class="name ">{{test_plan.create_date}}</div>
				
			</div>
			<div class="listinfo">
				<div class="title grey">Parent&nbsp;:</div>
				<div class="name ">
				{% if test_plan.parent.pk %}
					<a href="{% url 'test_plan_url_short' test_plan.parent.pk %}">{{ test_plan.parent.pk }}</a>
				{% else %}
					None
				{% endif %}
				</div>
			</div>
			<div class="listinfo">
				<div class="title"><a href="/admin/testplans/testplan/{{ test_plan.pk }}/history/">View Edit History</a></div>
			</div>
		</div>
		<div class="clear"></div>
	</div>
	<div id="plan_detail">
		<div class="Detailform border-1">
			<ul id="contentTab" class="content_tab">
				<li id="tab_document" class="tab">
					<a href="#document" title="document">Document</a>
				</li>
				<li id="tab_testcases" class="tab tab_focus">
					<a href="#testcases" title="testcases">Cases (<span id='run_case_count' class="js-testcases-count">{{ test_plan.run_case.count }}</span>/<span id='case_count'>{{ test_plan.case.count }}</span>)</a>
				</li>
				<li id="tab_reviewcases" class="tab">
					<a href="#reviewcases" title="reviewcases">Reviewing Cases (<span id='review_case_count' class="js-reviewcases-count">{{ test_plan.review_case.count }}</span>)</a>
				</li>
				<li id="tab_testruns"  class="tab">
					<a href="#testruns" title="testruns">Runs (<span id='run_count'>{{ test_plan.run.count }}</span>)</a>
				</li>
				<li id="tab_attachment" class="tab">
					<a href="#attachment" title="attachment">Attachments (<span id='attachment_count'>{% attachments_count test_plan %}</span>)</a>
				</li>
				<li id="tab_tag" class="tab">
					<a href="#tag" title="tag">Tags (<span id='tag_count'>{{ test_plan.tag.count }}</span>)</a>
				</li>
				<li id="tab_treeview" class="tab">
					<a href="#treeview" title="treeview">Tree View</a>
				</li>
			</ul>
			<div id="document" class="tab_list" style="display:none">
                            <div class="listinfo_doc_content">
                                <div id="display_summary" class="listinfo_doc">
                                {% if test_plan.text %}
                                    {{ test_plan.text|markdown2html }}
                                {% else %}
                                    <span style="color: #666">The document for this plan hasn't been written yet.</span>
                                {% endif %}
                                </div>
                            </div>
			</div>
			<div id="attachment" class="tab_list" style="display:none">
				{% include "plan/get_attachments.html" %}
			</div>
			<div id="testruns" class="tab_list" style="display:none;">
                            <!--
                                todo:
                                a temporary solution until we can convert the entire page to Patternfly
                                and figure out a way to re-use the search forms!
                             -->
                            <iframe src="{% url 'testruns-search' %}?nonav=1&plan={{ test_plan.pk }}&product={{ test_plan.product_id }}&product_version={{ test_plan.product_version_id }}"
                                    width="100%" height="1000px" scrolling="auto" frameBorder="0">
                            </iframe>
			</div>
			<div id="treeview" class="tab_list" style="display:none;">
				{% include "plan/get_treeview.html" %}
			</div>
			<div id="reviewcases" class="tab_list" style="display:none">
				<div class="ajax_loading"></div>
			</div>
			<div id="testcases" class="tab_list">
				<div class="ajax_loading"></div>
			</div>
			<div id="tag" class="tab_list" style="display:none">
				<div class="ajax_loading"></div>
			</div>
		</div>
	</div>
</div>
{% endblock %}
